<template>
  <div class="btn-list">
    <template v-for="item in btnList" :key="item.id">
      <el-tooltip class="box-item" effect="dark" :content="item.title" placement="left">
        <div @click="clickFn(item)" :class="['btn-item', item.id == activeNum ? 'btn-active' : '']">
          <i :class="['iconfont', item.iconfont]"></i>
        </div>
      </el-tooltip>
    </template>
  </div>
  <el-dialog title="无人机添加" v-model="airDroneDialogVisible" width="30%">
    <el-form :model="airForm" ref="ariform" :rules="rules" label-width="80px" :inline="false" size="small"
      :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form-item label="高度" prop="height">
        <el-input v-model="airForm.height"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span>
        <el-button @click="airDroneDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="airFromSubmit">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { getCurrentInstance, ref } from "vue";
import { ElMessage } from "element-plus";
import * as mars3d from "mars3d";
const Cesium = mars3d.Cesium;
import { getMarsMap } from "@/map/utils/mapCommon.js";

const { proxy } = getCurrentInstance();
const airDroneDialogVisible = ref(false);
const emit = defineEmits(["changePathUrl"]);
let MarsMap;
const activeNum = ref(0);
let btnList = [
  {
    iconfont: "icon-tianjiadian",
    id: 1,
    title: "添加点",
  },
  {
    iconfont: "icon-tianjiaxian",
    id: 2,
    title: "添加线",
  },
  {
    iconfont: "icon-mian",
    id: 3,
    title: "添加面",
  },
  {
    iconfont: "icon-guankongqu",
    id: 4,
    title: "添加管控区域",
  },
  {
    iconfont: "icon-fanghuoqiang",
    id: 5,
    title: "添加墙",
  },
  //   {
  //     iconfont: "icon-Twig",
  //     id: 6,
  //     title: "添加草",
  //   },
//   {
//     iconfont: "icon-shu1",
//     id: 7,
//     title: "添加树",
//   },
//   {
//     iconfont: "icon-wurenji",
//     id: 8,
//     title: "添加无人机",
//   },
];
const airForm = ref({
  height: "",
});
const rules = {
  height: [
    { trigger: "blur", required: true, message: "请输入高度" },
    { pattern: /^[1-9]\d*$/, message: "请输入大于0的数字" },
  ],
};
// 按钮操作
function clickFn(item) {
  if (!MarsMap) {
    MarsMap = getMarsMap();
  }
  MarsMap.graphicLayer.stopDraw();
  if (item.id == 1) {
    MarsMap.graphicLayer.startDraw({
      type: "billboard",
      style: {
        image: "marker/point-yellow.png",
        scale: 1,
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
      },
    });
  } else if (item.id == 2) {
    MarsMap.graphicLayer.startDraw({
      type: "polyline",
      style: {
        color: "#ff0000",
        width: 6,
      },
    });
  } else if (item.id == 3) {
    MarsMap.graphicLayer.startDraw({
      type: "polygon",
      style: {
        color: "#ff0000",
        opacity: 0.6,
      },
    });
  } else if (item.id == 4) {
    MarsMap.drawSolidArea();
  } else if (item.id == 5) {
    MarsMap.graphicLayer.startDraw({
      type: "thickWall",
      style: {
        color: "#ff0000",
        opacity: 0.3,
        width: 10,
      },
    });
  } else if (item.id == 6) {
    // emit("changePathUrl", "models/grass.gltf");
  } else if (item.id == 7) {
    emit("changePathUrl", "models/tree.gltf");
  } else if (item.id == 8) {
    airDroneDialogVisible.value = true;
  }
}

function airFromSubmit() {
  proxy.$refs["ariform"].validate((valid) => {
    if (valid) {
      airDroneDialogVisible.value = false;
      emit("changePathUrl", "models/air.glb", airForm.value.height);
      proxy.$refs["ariform"].resetFields();
    }
  });
}
</script>

<style lang="scss" scoped>
.btn-list {
  padding: 20% 0;
  position: absolute;
  right: 10px;
  top: 0%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;

  .btn-item {
    width: 40px;
    height: 40px;
    background-color: rgba(23, 13, 11, 0.8);
    text-align: center;
    line-height: 40px;
    border-radius: 10%;
    margin-bottom: 10px;
    cursor: pointer;

    .iconfont {
      padding: 5px;
      color: #fff;
      font-size: 20px;
    }
  }

  .btn-active {
    background-color: rgba(74, 136, 197, 0.8) !important;
  }
}
</style>
